/*
 * Base class for all field validators
 *  
 * Copyright (C) 2011 Antti Leppä / Otavan Opisto
 * http://www.otavanopisto.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 3 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */
fi.internetix.validation.FieldValidator = Class.create(
  /** @lends fi.internetix.validation.FieldValidator# */ 
  {
  /**
  * Class constructor
  * @class Base class for all field validators
  * @constructs
  */
  initialize : function() {},
  /**
   * Validates a field and returns it's status
   * 
   * @param field field to be validated
   * @returns 
   *   <table>
   *     <tr>
   *       <td>fi.internetix.validation.FieldValidator#STATUS_UNKNOWN</td><td>&nbsp;&nbsp;If field cannot be validated</td>
   *     </tr>
   *     <tr>
   *       <td>fi.internetix.validation.FieldValidator#STATUS_VALID</td><td>&nbsp;&nbsp;If field is valid</td>
   *     </tr>
   *     <tr>
   *       <td>fi.internetix.validation.FieldValidator#STATUS_INVALID</td><td>&nbsp;&nbsp;If field is invalid</td>
   *     </tr>
   *   </table>
   */
  validate: function (field) {},
  /**
   * Returns field type
   * 
   * @returns
   *   <table>
   *     <tr>
   *       <td>fi.internetix.validation.FieldValidator.TYPE_NORMAL</td><td>&nbsp;&nbsp;For normal fields</td>
   *     </tr>
   *     <tr>
   *       <td>fi.internetix.validation.FieldValidator.TYPE_LINKED</td><td>&nbsp;&nbsp;For linked fields</td>
   *     </tr>
   *   </table>
   *   
   */
  getType: function () {
    return null;
  },
  /**
   * Returns class name of elements validator validates
   */
  getClassName: function () {
  },
  /**
   * @private   
   */
  _getFieldValue: function (field) {
    if (field.type == 'checkbox')
      return field.checked ? '0' : '1';
    else
      return field.value;
  }
});

/** @class **/
Object.extend(fi.internetix.validation.FieldValidator, 
  /** @lends fi.internetix.validation.FieldValidator# */   
  {
  /**
   * Invalid status
   */
  STATUS_UNDEFINED: -1,
  /**
   * Unknown status
   */
  STATUS_UNKNOWN: 0,
  /**
   * Invalid status
   */
  STATUS_INVALID: 1,
  /**
   * Valid status
   */
  STATUS_VALID: 2,
  /**
   * Element is hidden and should be considered "valid".
   */
  STATUS_HIDDEN: 3,

  /**
   * Normal validator
   */
  TYPE_NORMAL:0,
  /**
   * Mandatory validator
   */
  TYPE_MANDATORY:1,
  /**
   * Linked validator
   */
  TYPE_LINKED:2    
});